/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package formulagraph;

import formulagraph.lineas.Continua;
import formulagraph.lineas.ExtremosLinea;
import formulagraph.lineas.Linea;
import java.util.Iterator;
import java.util.List;
import mathmlcalculator.MathMLCalculator;

/**
 *
 * @author soler4888
 */
public class Formula {

    private String mathMLpath;
    private String mathMLfile;
    private List<Punto> puntos;
    private Dominio dominio;
    private Linea linea;
    private double incremento;

    public Formula(String mathMLpath, String mathMLfile, Dominio dominio, Linea linea, double incremento) throws Exception {
        this.mathMLpath = mathMLpath;
        this.mathMLfile = mathMLfile;
        this.dominio = dominio;
        this.linea = linea;
        this.incremento = incremento;
        MathMLCalculator mmlc = new MathMLCalculator(mathMLpath, mathMLfile);
        this.puntos = mmlc.CalcularPuntos(dominio.getInicio(), dominio.getFin(), incremento);
    }

    public Formula(String mathMLpath, String mathMLfile, Dominio dominio, double incremento) throws Exception {
        this(mathMLpath, mathMLfile, dominio, new Continua(), incremento);
    }

    public Formula(String mathMLpath, String mathMLfile, Dominio dominio, Linea linea) throws Exception {
        this(mathMLpath, mathMLfile, dominio, linea, 1.0f);
    }

    public Formula(String mathMLpath, String mathMLfile, Dominio dominio) throws Exception {
        this(mathMLpath, mathMLfile, dominio, new Continua(), 1.0f);
    }
    
    public Linea getLinea() {
        return linea;
    }

    public double getIncremento() {
        return incremento;
    }

    public String getMathMLfile() {
        return mathMLfile;
    }

    public String getMathMLpath() {
        return mathMLpath;
    }

    public Dominio getDominio() {
        return dominio;
    }

    public List<Punto> getPuntos() {
        return puntos;
    }

    public void setColorLinea(Colores colorLinea) {
        linea.setColorLinea(colorLinea);
    }

    public void setAnchuraLinea(double anchuraLinea) {
        linea.setAnchuraLinea(anchuraLinea);
    }

    public void setExtremoLinea(ExtremosLinea extremoLinea) {
        linea.setExtremoLinea(extremoLinea);
    }

    public void setLinea(Linea linea) {
        this.linea = linea;
    }

    public String dibujar() {
        StringBuilder builder = new StringBuilder();

        builder.append("<polyline points=\"");
        Iterator<Punto> it = puntos.iterator();
        while (it.hasNext()) {
            Punto p = it.next();
            builder.append(p.dibujar()).append(" ");
        }
        builder.deleteCharAt(builder.length() - 1);
        builder.append("\" style=\"fill:none\" ");
        builder.append(linea.dibujar());
        builder.append(" />");

        return builder.toString();
    }
}
